package com.ruoyi.web.controller.system.Fdongbei;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.Fdongbei.domain.TbGuozhong;
import com.ruoyi.system.Fdongbei.domain.TbHuayan;
import com.ruoyi.system.Fdongbei.domain.vo.resvo.GyshzpjhyResVo;
import com.ruoyi.system.Fdongbei.domain.vo.resvo.HuayanYuan2ResVo;
import com.ruoyi.system.Fdongbei.domain.vo.resvo.HuayanYuanResVo;
import com.ruoyi.system.Fdongbei.service.ITbHuayanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 化验--》Controller
 * 
 * @author ruoyi
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/system/huayan")
public class TbHuayanController extends BaseController
{
    @Autowired
    private ITbHuayanService tbHuayanService;

    /**
     * 查询化验--》列表
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbHuayan tbHuayan)
    {
        startPage();
        List<TbHuayan> list = tbHuayanService.selectTbHuayanList(tbHuayan);
        return getDataTable(list);
    }


    /**
     * 化验汇总
     * @param gyshzpjhyResVo
     * @return
     */
    @GetMapping("/listhz")
    public TableDataInfo list(GyshzpjhyResVo gyshzpjhyResVo)
    {
        startPage();
        List<GyshzpjhyResVo> list = tbHuayanService.selectTbHuayanhzList(gyshzpjhyResVo);
        return getDataTable(list);
    }
    /**
     * 化验汇总原
     * @param huayanYuanResVo
     * @return
     */
    @GetMapping("/listyuan")
    public TableDataInfo listyuan(HuayanYuanResVo huayanYuanResVo)
    {
        startPage();
        List<HuayanYuanResVo> list = tbHuayanService.selectTbHuayanyuanList(huayanYuanResVo);
        return getDataTable(list);
    }

    /**
     * 化验汇总原2
     * @param huayanYuan2ResVo
     * @return
     */
    @GetMapping("/listyuan2")
    public TableDataInfo listyuan2(HuayanYuan2ResVo huayanYuan2ResVo)
    {
        startPage();
        List<HuayanYuan2ResVo> list = tbHuayanService.selectTbHuayanyuan2List(huayanYuan2ResVo);
        return getDataTable(list);
    }


    /**
     * 导出化验--》列表
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:export')")
    @Log(title = "化验--》", businessType = BusinessType.EXPORT)
    @PostMapping("/exportyuan")
    public void export(HttpServletResponse response, HuayanYuanResVo huayanYuanResVo)
    {
        List<HuayanYuanResVo> list = tbHuayanService.selectTbHuayanyuanList(huayanYuanResVo);
        ExcelUtil<HuayanYuanResVo> util = new ExcelUtil<HuayanYuanResVo>(HuayanYuanResVo.class);
        util.exportExcel(response, list, "原-化验日汇总");

    }


    /**
     * 导出化验--》列表
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:export')")
    @Log(title = "原-化验日汇总2", businessType = BusinessType.EXPORT)
    @PostMapping("/exportyuan2")
    public void export(HttpServletResponse response, HuayanYuan2ResVo huayanYuan2ResVo)
    {
        List<HuayanYuan2ResVo> list = tbHuayanService.selectTbHuayanyuan2List(huayanYuan2ResVo);
        ExcelUtil<HuayanYuan2ResVo> util = new ExcelUtil<>(HuayanYuan2ResVo.class);
        util.exportExcel(response, list, "原-化验日汇总2");

    }
    /**
     * 导出化验--》列表
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:export')")
    @Log(title = "化验--》", businessType = BusinessType.EXPORT)
    @PostMapping("/exportzh")
    public void export(HttpServletResponse response, GyshzpjhyResVo gyshzpjhyResVo)
    {
        List<GyshzpjhyResVo> list = tbHuayanService.selectTbHuayanhzList(gyshzpjhyResVo);
        ExcelUtil<GyshzpjhyResVo> util = new ExcelUtil<GyshzpjhyResVo>(GyshzpjhyResVo.class);
        util.exportExcel(response, list, "供应商平均汇总化验");

    }
    // 返回过重表信息
    @GetMapping("/gzlist")
    public AjaxResult gzlist(String czbh)
    {
        startPage();
        TbGuozhong tbGuozhong = tbHuayanService.selectTbGuozhong(czbh);
        return success(tbGuozhong);
    }

    /**
     * 导出化验--》列表
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:export')")
    @Log(title = "化验--》", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbHuayan tbHuayan)
    {
        List<TbHuayan> list = tbHuayanService.selectTbHuayanList(tbHuayan);
        ExcelUtil<TbHuayan> util = new ExcelUtil<TbHuayan>(TbHuayan.class);
        util.exportExcel(response, list, "化验--》数据");
    }

    /**
     * 获取化验--》详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:huayan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbHuayanService.selectTbHuayanById(id));
    }

    /**
     * 新增化验--》
     */
    @PreAuthorize("@ss.hasPermi('system:huayan:add')")
    @Log(title = "化验--》", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbHuayan tbHuayan)
    {
        return toAjax(tbHuayanService.insertTbHuayan(tbHuayan));
    }

    /**
     * 修改化验--》
     */
    @PreAuthorize("@ss.hasPermi('system:huayan:edit')")
    @Log(title = "化验--》", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbHuayan tbHuayan)
    {
        return toAjax(tbHuayanService.updateTbHuayan(tbHuayan));
    }

    /**
     * 删除化验--》
     */
    @PreAuthorize("@ss.hasPermi('system:huayan:remove')")
    @Log(title = "化验--》", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbHuayanService.deleteTbHuayanByIds(ids));
    }


    /**
     * 增加化验打印次数
     * @param czbh
     * @return
     */
    @Log(title = "增加化验打印次数", businessType = BusinessType.UPDATE)
    @GetMapping("/dycs/{czbh}")
    public AjaxResult updateDycs(@PathVariable("czbh") String czbh){
        System.out.println(czbh+"-------------");
        return toAjax(tbHuayanService.upDateGuozhongDycs(czbh));
    }

}
